package org.jpro.modules.system.web;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jpro.annotation.FormatResponseBodyAnnotation;
import org.jpro.common.web.BaseController;
import org.jpro.modules.system.service.ILogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 日志controller
 */
@Controller
@RequestMapping("/system/log")
public class LogController extends BaseController {

    @Autowired
    private ILogService logService;

    /**
     * 默认页面
     * @return
     */
    @RequestMapping(method = RequestMethod.GET)
    public String list() {
        return "system/logList";
    }

    /**
     * 获取日志json
     */
    @ResponseBody
    @RequestMapping("json")
    @RequiresPermissions("sys:log:view")
    @FormatResponseBodyAnnotation(false)
    public Map<String, Object> getData(String operationCode, String description, Date gtCreateDate, Date ltCreateDate) {
        return getEasyUIData(logService.search(operationCode, description, gtCreateDate, ltCreateDate, super.getPageRequest()));
    }

    /**
     * 删除日志
     * @param id
     */
    @ResponseBody
    @RequiresPermissions("sys:log:delete")
    @RequestMapping(value = "delete/{id}")
    public String delete(@PathVariable("id") Integer id) {
        logService.delete(id);
        return "success";
    }

    /**
     * 批量删除日志
     * @param idList
     */
    @ResponseBody
    @RequestMapping(value = "delete", method = RequestMethod.POST)
    public void delete(@RequestBody List<Integer> idList) {
        logService.deleteLog(idList);
    }

    /**
     * 导出excel
     * @param request
     * @param response
     * @throws Exception
     */
    @RequestMapping("exportExcel")
    public void exportExcel(HttpServletRequest request, HttpServletResponse response) throws Exception {
        /*response.setContentType("application/msexcel;charset=GBK");
        
        List<Log> list = logService.getAll();//获取数据
        
        String title = "log";
        String[] hearders = new String[] {"操作编码", "详细描述", "执行时间(mm)", "操作系统", "浏览器", "IP","MAC","操作者","操作时间"};//表头数组
        String[] fields = new String[] {"operationCode", "description", "executeTime", "os", "browser", "ip","mac","creater","createDate"};//People对象属性数组
        TableData td = ExcelUtils.createTableData(list, ExcelUtils.createTableHeader(hearders),fields);
        JsGridReportBase report = new JsGridReportBase(request, response);
        report.exportToExcel(title, "admin", td);*/
    }
}
